package Demo1;

public class T17 {
    public static void main(String[] args) {
        Object a = new Object();
        Object b = new Object();
        Thread thread = new Thread(()->{
            synchronized (a){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
//                尝试获取 b 造成死锁
                synchronized (b){
                    System.out.println(1111);
                }
            }
        });
        Thread thread1 = new Thread(()->{
            synchronized (b){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
//                尝试获取 a 造成死锁
                synchronized (a){
                    System.out.println(2222);
                }
            }
        });
        thread1.start();
        thread.start();
    }
}
